﻿// Write a method that counts how many times given number appears in given array. 
// Write a test program to check if the method is working correctly.

using System;
using System.Collections;

public class CountNumberInArray
{
    static void Main()
    {
        int[] intArray = { 1, 1, 6, 3, 4, 5, 0, -4, 4, 0, -5, 3, 9, 15 };
        int numberToCount = 4;

        int count = CountItem(numberToCount, intArray);
        Console.WriteLine("Number {0} appears {1} times in Array.", numberToCount, count);
    }

    public static int CountItem(object itemToCount, IEnumerable collection)
    {
        int count = 0;
        foreach (var item in collection)
        {
            if (item.Equals(itemToCount))
            {
                count++;
            }
        }

        return count;
    }
}